package com.mmg.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.mmg.spzx.manager.service.UserInfoService;
import com.mmg.spzx.model.dto.user.UserInfoDto;
import com.mmg.spzx.model.entity.user.UserInfo;
import com.mmg.spzx.model.vo.common.Result;
import com.mmg.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户管理")
@RestController
@RequestMapping("/admin/user/userInfo/")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @Operation(summary = "更新用户状态")
    @PutMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id") Integer id,
                               @PathVariable("status") Integer status) {
        userInfoService.updateStatus(id, status);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "条件分页查询")
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             UserInfoDto userInfoDto) {
        if (pageNum == null || pageSize == null) {
            pageNum = 1;
            pageSize = 5;
        }
        PageInfo<UserInfo> pageInfo = userInfoService.findByPage(pageNum, pageSize, userInfoDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
}
